package per.songyu.goods.dao;

import org.apache.ibatis.annotations.*;
import per.songyu.goods.pojo.Goods;


import java.util.List;

@Mapper
public interface GoodsDao {

    /**
     * 查询所有商品信息
     * @return 所有商品
     * mybatis提供两种查询方式
     * 1）简单sql，可以直接使用注解方式
     * 2）复杂sql，使用mapper映射
     */

    @Select("select * from tb_goods")
    List<Goods> findGoods();

    @Select("select * from tb_goods where id=#{id}")
    Goods findGoodsById(int id);

    @Select("select * from tb_goods")
    List<Goods> findObjects();

    @Delete("delete from tb_goods where id=#{id}")
    Integer deleteById(Integer id);

    @Insert("insert into tb_goods(name,remark,createdTime) values(#{name},#{remark},now())")
    int insert(Goods entity);

    @Update("update tb_goods set name=#{name},remark=#{remark},createdTime=now() where id=#{id}")
    int updateById(Goods goods);
}
